<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "goods".
 *
 * @property integer $g_id
 * @property integer $gf_id
 * @property integer $s_id
 * @property string $g_name
 * @property string $g_price
 * @property string $g_num
 * @property string $g_intrlduce
 * @property string $g_img
 * @property string $img1
 * @property string $img2
 * @property string $img3
 * @property string $img4
 * @property string $g_data
 * @property string $g_status
 * @property string $g_shenhe
 *
 * @property ScGoodsfen $gf
 * @property Shop $s
 * @property Gouwuche[] $gouwuches
 * @property Orders[] $orders
 * @property ScAttr[] $scAttrs
 * @property ScAudit[] $scAudits
 * @property ScTotal[] $scTotals
 */
class Goods extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'goods';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['g_id', 'g_name', 'g_price', 'g_num', 'g_intrlduce', 'g_img', 'g_data', 'g_status', 'g_shenhe'], 'required'],
            [['g_id', 'gf_id', 's_id'], 'integer'],
            [['g_price', 'g_num', 'g_status', 'g_shenhe'], 'number'],
            [['g_intrlduce'], 'string'],
            [['g_data'], 'safe'],
            [['g_name'], 'string', 'max' => 50],
            [['g_img', 'img1', 'img2', 'img3', 'img4'], 'string', 'max' => 100]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'g_id' => '商品ID',
            'gf_id' => '分类ID',
            's_id' => '属性ID',
            'g_name' => '商品名称',
            'g_price' => '价格',
            'g_num' => '库存',
            'g_intrlduce' => '商品介绍',
            'g_img' => '主图',
            'img1' => '细节图1',
            'img2' => '细节图2',
            'img3' => '细节图3',
            'img4' => '细节图4',
            'g_data' => 'G Data',
            'g_status' => 'G Status',
            'g_shenhe' => 'G Shenhe',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getGf()
    {
        return $this->hasOne(ScGoodsfen::className(), ['gf_id' => 'gf_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getS()
    {
        return $this->hasOne(Shop::className(), ['s_id' => 's_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getGouwuches()
    {
        return $this->hasMany(Gouwuche::className(), ['g_id' => 'g_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getOrders()
    {
        return $this->hasMany(Orders::className(), ['g_id' => 'g_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getScAttrs()
    {
        return $this->hasMany(ScAttr::className(), ['g_id' => 'g_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getScAudits()
    {
        return $this->hasMany(ScAudit::className(), ['g_id' => 'g_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getScTotals()
    {
        return $this->hasMany(ScTotal::className(), ['g_id' => 'g_id']);
    }
}
